import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:wu_you/data/repository/mall_repository.dart';
import 'package:wu_you/l10n/messages.dart';
import 'package:wu_you/model/mall/order_model.dart';
import 'package:wu_you/page/dialog/dialog.dart';
import 'package:wu_you/res/colors.dart';
import 'package:wu_you/state/bloc/http_bloc.dart';
import 'package:wu_you/state/bloc/mall_bloc.dart';
import 'package:wu_you/utils/navigator_util.dart';
import 'package:wu_you/utils/utils.dart';
import 'package:wu_you/widgets/appbar_leading.dart';
import 'package:wu_you/widgets/http_list_widget.dart';
import 'package:wu_you/utils/extension_utils.dart';
import 'package:wu_you/widgets/http_status_widget.dart';

///商城订单列表
class ProductOrderListPage extends StatefulWidget{
  final int index;
  ProductOrderListPage({Key key,this.index = 0}):super(key: key);
  @override
  ProductOrderListPageState createState() => ProductOrderListPageState();
}
class ProductOrderListPageState extends State<ProductOrderListPage>{
  List<String> _tabs = [];

  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    _tabs.clear();
    _tabs = ['${message['user6']}','${message['user7']}','${message['user8']}','${message['user9']}'];
    return DefaultTabController(
      length: _tabs.length,
      initialIndex: widget.index,
      child: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          leading: AppBarLeading.leading("ic_mall_back"),
          title: Text("${message['user5']}"),
        ),
        body: Column(
          children: [
            TabBar(
              labelColor: AppColors.primaryColor,
              indicatorColor: AppColors.primaryColor,
              unselectedLabelColor: AppColors.textColor,
              indicatorSize: TabBarIndicatorSize.label,
              labelStyle: TextStyle(fontSize: 14),
              // isScrollable: true,
              tabs: _tabs
                  .map((e) => Tab(
                text: e,
              ))
                  .toList(),
            ),
            Padding(
              padding: EdgeInsets.only(left: 15, right: 15),
              child: Divider(
                thickness: 1,
              ),
            ),
            Expanded(
                child: TabBarView(
                  children: [
                    BottomListView(type: "全部",),
                    BottomListView(type: "待发货",),
                    BottomListView(type: "待收货",),
                    BottomListView(type: "已完成",),
                  ]
                ))
          ],
        ),
      ),
    );
  }
}

class BottomListView extends StatefulWidget{
  final String type;
  BottomListView({Key key,this.type}):super(key: key);
  @override
  BottomListViewState createState() => BottomListViewState();
}
class BottomListViewState extends State<BottomListView>{
  String state;
  BuildContext ctx;
  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    switch (widget.type) {
      case "全部":
        state = "0";
        break;
      case "待发货":
        state = "1";
        break;
      case "待收货":
        state = "2";
        break;
      case "已完成":
        state = "3";
        break;
    }
    return HttpListWidget<OrderListModel, MallOrderListBloc>(
      creator: (context) => MallOrderListBloc(),
      onObtainData: (context, page) {
        BlocProvider.of<MallOrderListBloc>(context).add(MallOrderListEvent(state, page));
      },
      successBuilder: (context, data) {
        ctx = context;
        return ListView.builder(
            itemCount: data.length,
            itemBuilder: (context, index) {
              OrderListModel model = data[index];
              String cancelName;
              String btnName = "${message['product22']}";
              switch(int.parse(model.order_state)){
                case 1:
                  btnName = "${message['product22']}";
                  break;
                case 2:
                  btnName = "${message['product22']}";
                  break;
                case 3:
                  btnName = "${message['product22']}";
                  cancelName = "${message['product23']}";
                  break;
              }
              return GestureDetector(
                  onTap: () {
                    NavigatorUtil.navigateToPage(context, OrderItemDetail(id: model.order_id,));
                  },
                  child: Card(
                    margin: EdgeInsets.only(left: 15, right: 15, top: 15),
                    elevation: 1,
                    child: Padding(
                      padding: EdgeInsets.only(left: 10, right: 10),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox.fromSize(
                            size: Size(double.infinity, 40),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  '${message['product20']}：${model.create_time}',
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 14,
                                      color: AppColors.textColor),
                                ),
                                // Row(
                                //   mainAxisSize: MainAxisSize.min,
                                //   children: [
                                //     Text("联系商家",style: TextStyle(fontSize: 13,color: AppColors.primaryColor),),
                                //     Icon(Icons.phone,size: 16,color: AppColors.textHintColor,)
                                //   ],
                                // ).addGesture(() {
                                //   // launch("tel://${model.merchant.cont_phone}");
                                // })
                              ],
                            ),
                          ),
                          Divider(
                            thickness: 1,
                          ),
                          // Chip(
                          //   padding: EdgeInsets.zero,
                          //   labelPadding: EdgeInsets.zero,
                          //   avatar: SizedBox.fromSize(
                          //       size: Size(20, 20),
                          //       child: Image.asset(
                          //         Utils.getImgPath("store"),
                          //       )),
                          //   label: Text("",
                          //       style: TextStyle(color: AppColors.textColor)),
                          //   shape: RoundedRectangleBorder(),
                          //   backgroundColor: Colors.white,
                          // ),
                          Container(
                            width: double.infinity,
                            color: Colors.transparent,
                            padding: EdgeInsets.only(top: 8,bottom: 8),
                            child: ListTile(
                              contentPadding:
                              EdgeInsets.symmetric(horizontal: 0),
                              leading: Stack(
                                children: [
                                  ClipRRect(
                                      borderRadius:
                                      BorderRadius.all(Radius.circular(5)),
                                      child: model.file_url == "" ?
                                      Image.asset(Utils.getImgPath("ic_logo")):
                                      Image.network(
                                        model.file_url,
                                        fit: BoxFit.fill,
                                      )),
                                ],
                              ),
                              title: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    model.goods.name,
                                    maxLines: 1,
                                    overflow: TextOverflow.ellipsis,
                                    style: TextStyle(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 14,
                                        color: AppColors.textColor),
                                  ),
                                  Text(
                                    model.sku.sku_name,
                                    maxLines: 2,
                                    overflow: TextOverflow.ellipsis,
                                    style: TextStyle(
                                        fontSize: 14,
                                        color:
                                        AppColors.textSecondaryColor),
                                  ),
                                  Row(
                                    mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(
                                        "${model.order_price}",
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: AppColors.primaryColor),
                                      ),
                                      Text(
                                        "x ${model.order_number}",
                                        style: TextStyle(
                                            fontWeight: FontWeight.normal,
                                            fontSize: 14,
                                            color: AppColors.textColor),
                                      ),
                                    ],
                                  )
                                ],
                              ),
                            ),
                          ),
                          SizedBox(height: 5,),
                          Divider(
                            thickness: 1,
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 10, bottom: 10),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                RichText(
                                  text: TextSpan(children: [
                                    TextSpan(
                                      text: '${message['product21']}：',
                                      style: TextStyle(
                                          fontSize: 13,
                                          color: AppColors.textSecondaryColor),
                                    ),
                                    TextSpan(
                                      text: itemPrice(model),
                                      style: TextStyle(
                                          fontSize: 14,
                                          color: AppColors.primaryColor,
                                          fontWeight: FontWeight.bold
                                      ),
                                    ),
                                  ]),
                                ),
                                SizedBox(width: 8,),
                                // RichText(
                                //   text: TextSpan(children: [
                                //     TextSpan(
                                //       text: '手续费：',
                                //       style: TextStyle(
                                //           fontSize: 13,
                                //           color: AppColors.textSecondaryColor),
                                //     ),
                                //     TextSpan(
                                //       text: _comPrice(model),
                                //       style: TextStyle(
                                //           fontSize: 14,
                                //           color: AppColors.primaryColor,
                                //           fontWeight: FontWeight.bold),
                                //     ),
                                //   ]),
                                // )
                              ],
                            ),
                          ),
                          Container(
                            width: double.infinity,
                            height: 50,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text(
                                  "",
                                  style: TextStyle(
                                      fontSize: 12,
                                      color: AppColors.textHintColor),
                                ),
                                Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                  children: [
                                    Offstage(
                                      offstage:
                                      cancelName != null ? false : true,
                                      child: ElevatedButton(
                                        child: Text(cancelName ?? "${message['product36']}"),
                                        onPressed: () {
                                          _deleteOrder(model);
                                        },
                                        style: ButtonStyle(
                                          minimumSize:
                                          MaterialStateProperty.all(
                                              Size(80, 30)),
                                          shape: MaterialStateProperty.all(
                                              StadiumBorder(
                                                side: BorderSide(
                                                    color: AppColors
                                                        .textSecondaryColor),
                                              )),
                                          backgroundColor:
                                          MaterialStateProperty.all(
                                              Colors.white),
                                          foregroundColor:
                                          MaterialStateProperty.all(
                                              AppColors.textSecondaryColor),
                                        ),
                                      ),
                                    ),
                                    SizedBox.fromSize(
                                      size: Size(10, 1),
                                    ),
                                    ElevatedButton(
                                      child: Text(btnName),
                                      onPressed: () {
                                        NavigatorUtil.navigateToPage(context, OrderItemDetail(id: model.order_id,)).then((value){
                                          if (value != null) {
                                            BlocProvider.of<MallOrderListBloc>(ctx).add(MallOrderListEvent(state, 1));
                                          }
                                        });
                                      },
                                      style: ButtonStyle(
                                          minimumSize:
                                          MaterialStateProperty.all(
                                              Size(80, 30))),
                                    ),
                                  ],
                                )
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  ));
            });
      }
    );
  }

  String itemPrice(OrderListModel model){
    return "无忧积分:${model.order_total_price}";
    if(model.order_no.startsWith("xf")){
      return "消费积分:${model.order_total_price}";
    }else if(model.order_no.startsWith("ll")){
      return "无忧积分:${model.order_total_price}";
    }else{
      return "消费积分:${model.order_total_price}";
    }
  }

  _deleteOrder(OrderListModel model){
    showDialog(
      context: context,
      builder: (ctx) {
        return PrettyDialog(
          content: Column(
            children: [
              Text(
                "${message['product24']}？",
                style: TextStyle(
                    color: Colors.white, fontSize: 16),
                textAlign: TextAlign.center,
              ),
              SizedBox(
                height: 5,
              ),
              Text(
                "${message['product25']}",
                style: TextStyle(
                    color: Colors.white, fontSize: 13),
                textAlign: TextAlign.center,
              )
            ],
          ),
          icon: Image.asset(
              Utils.getImgPath("ic_forget_password"),
              width: 80,
              height: 80,
              fit: BoxFit.fill,
              color: Colors.white),
          background:
          AssetImage(Utils.getImgPath("ic_alert_dialog")),
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [
              AppColors.secondColor,
              AppColors.primaryColor
            ],
          ),
          actions: [
            TextButton(
              child: Text("${message['product26']}",
                  style: TextStyle(
                      fontSize: 15,
                      color: AppColors.textColor)),
              onPressed: () {
                Navigator.of(ctx).pop();
              },
            ),
            TextButton(
              child: Text("${message['product27']}",
                  style: TextStyle(
                      fontSize: 15,
                      color: AppColors.primaryColor)),
              onPressed: () {

                LoadingApi.func(MallRepository.deleteMallOrderAction(model.order_id), ctx, complete: (value) {
                  ToastUtils.show("${message['Success']}", ctx);
                  Navigator.of(ctx).pop();
                  BlocProvider.of<MallOrderListBloc>(ctx).add(MallOrderListEvent(state, 1));
                  // Navigator.of(ctx).pop();
                },error: (e){
                  ToastUtils.show("$e", context);
                });
              },
            ),
          ],
        );
      },
    );
  }
}



class OrderItemDetail extends StatefulWidget{
  final String id;
  OrderItemDetail({Key key,this.id}):super(key: key);
  @override
  OrderItemDetailState createState() => OrderItemDetailState();
}
class OrderItemDetailState extends State<OrderItemDetail>{
  String rpName;
  String rpPhone;
  String rpAddress;
  bool flag = false;

  var message;
  @override
  Widget build(BuildContext context) {
    message = AppLocalizations.of(context);
    double width = MediaQuery.of(context).size.width;
    return Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          leading: AppBarLeading.leading("ic_mall_back"),
          title: Text("${message['product28']}"),
          flexibleSpace: Container(
            height: 300,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
                colors: [AppColors.primaryColor, AppColors.secondColor],
              ),
            ),
          ),
        ),
        body: HttpWidget<OrderListModel, OrderDetailBloc>(
            create: (context) => OrderDetailBloc()..add(IdStrHttpEvent(widget.id)),
            child: (context, data) {
              if (flag == false) {
                rpName = data.receipt_name;
                rpPhone = data.receipt_phone;
                rpAddress = data.receipt_address;
              }
              Widget boxBottomChild;
              switch(int.parse("${data.order_state}")){
                case 0: ///返回
                  boxBottomChild = Container(
                      decoration: BoxDecoration(
                        gradient: LinearGradient(colors: [
                          AppColors.primaryColor,
                          AppColors.secondColor
                        ]),
                      ),
                      width: double.infinity,
                      height: 50,
                      child: TextButton(
                        child: Text("${message['product37']}"),
                        style: ButtonStyle(
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white),
                          // shape: MaterialStateProperty.all(BeveledRectangleBorder()),
                          shape:
                          MaterialStateProperty.all(BeveledRectangleBorder()),
                        ),
                        onPressed: () {
                          Navigator.pop(context);
                        },
                      ));
                  break;
                case 1:///返回
                  boxBottomChild = Container(
                      decoration: BoxDecoration(
                        gradient: LinearGradient(colors: [
                          AppColors.primaryColor,
                          AppColors.secondColor
                        ]),
                      ),
                      width: double.infinity,
                      height: 50,
                      child: TextButton(
                        child: Text("${message['product37']}"),
                        style: ButtonStyle(
                          foregroundColor:
                          MaterialStateProperty.all(Colors.white),
                          // shape: MaterialStateProperty.all(BeveledRectangleBorder()),
                          shape:
                          MaterialStateProperty.all(BeveledRectangleBorder()),
                        ),
                        onPressed: () {
                          Navigator.pop(context);
                        },
                      ));
                  break;
                case 2:///查看物流 / 确认收货
                  boxBottomChild = Container(
                      decoration: BoxDecoration(
                        gradient: LinearGradient(colors: [
                          AppColors.primaryColor,
                          AppColors.secondColor
                        ]),
                      ),
                      width: double.infinity,
                      height: 50,
                      child: Row(
                        children: [
                          Flexible(
                            flex: 1,
                            child: ElevatedButton(
                              child: Text("${message['product38']}"),
                              style: ButtonStyle(
                                foregroundColor:
                                MaterialStateProperty.all(Colors.white),
                                shape: MaterialStateProperty.all(BeveledRectangleBorder()),
                              ),
                              onPressed: () {
                                ToastUtils.show("暂无物流信息", context);
                                // NavigatorUtil.navigateToPage(context, LogisticsInfoView(orderId: data.order_id,orderNum: data.order_no,address: data.receipt_address,type: 1,));
                              },
                            ),
                          ),
                          Container(
                            width: 1,
                            color: Colors.white,
                          ),
                          Flexible(
                              flex: 1,
                              child: ElevatedButton(
                                child: Text("${message['product32']}"),
                                style: ButtonStyle(
                                  foregroundColor:
                                  MaterialStateProperty.all(Colors.white),
                                  // shape: MaterialStateProperty.all(BeveledRectangleBorder()),
                                  shape: MaterialStateProperty.all(
                                      BeveledRectangleBorder()),
                                ),
                                onPressed: () {
                                  showDialog(
                                    context: context,
                                    builder: (ctx) {
                                      return PrettyDialog(
                                        content: Column(
                                          children: [
                                            Text(
                                              "${message['product39']}？",
                                              style: TextStyle(
                                                  color: Colors.white,
                                                  fontSize: 14),
                                              textAlign: TextAlign.center,
                                            ),
                                            SizedBox(
                                              height: 4,
                                            ),
                                            // Text(
                                            //   "请收到商品检查无误后再确认收货！",
                                            //   style: TextStyle(
                                            //       color: Colors.white,
                                            //       fontSize: 12),
                                            //   textAlign: TextAlign.center,
                                            // )
                                          ],
                                        ),
                                        icon: Image.asset(
                                            Utils.getImgPath("ic_forget_password"),
                                            width: 76,
                                            height: 76,
                                            fit: BoxFit.fill,
                                            color: Colors.white),
                                        background: AssetImage(
                                            Utils.getImgPath("ic_alert_dialog")),
                                        gradient: LinearGradient(
                                          begin: Alignment.topCenter,
                                          end: Alignment.bottomCenter,
                                          colors: [
                                            AppColors.secondColor,
                                            AppColors.primaryColor
                                          ],
                                        ),
                                        actions: [
                                          TextButton(
                                            child: Text("${message['product26']}",
                                                style: TextStyle(
                                                    fontSize: 15,
                                                    color:
                                                    AppColors.textHintColor)),
                                            onPressed: () {
                                              Navigator.of(ctx).pop();
                                            },
                                          ),
                                          TextButton(
                                            child: Text("${message['product27']}",
                                                style: TextStyle(
                                                    fontSize: 15,
                                                    color: AppColors.primaryColor)),
                                            onPressed: () {
                                              Navigator.of(ctx).pop();
                                              LoadingApi.func(MallRepository.confirmOrderAction(data.order_id), context, complete: (value) {
                                                ToastUtils.show("${message['Success']}", ctx);
                                                Navigator.of(context).pop(1);
                                              },error: (e){
                                                ToastUtils.show("$e", ctx);
                                              });
                                            },
                                          ),
                                        ],
                                      );
                                    },
                                  );
                                },
                              ))
                        ],
                      )
                  );
                  break;
                case 3:///查看物流 / 删除订单
                  boxBottomChild = Container(
                      decoration: BoxDecoration(
                        gradient: LinearGradient(colors: [
                          AppColors.primaryColor,
                          AppColors.secondColor
                        ]),
                      ),
                      height: 50,
                      child: Row(
                        children: [
                          Flexible(
                            flex: 1,
                            child: ElevatedButton(
                              child: Text("${message['product38']}"),
                              style: ButtonStyle(
                                foregroundColor:
                                MaterialStateProperty.all(Colors.white),
                                shape: MaterialStateProperty.all(BeveledRectangleBorder()),
                              ),
                              onPressed: () {
                                // ToastUtils.show("暂无物流信息", context);
                                // NavigatorUtil.navigateToPage(context, LogisticsInfoView(orderId: data.order_id,orderNum: data.order_no,address: data.receipt_address,type: 1,));
                              },
                            ),
                          ),
                          Container(
                            width: 1,
                            color: Colors.white,
                          ),
                          Flexible(
                              flex: 1,
                              child: ElevatedButton(
                                child: Text("${message['product23']}"),
                                style: ButtonStyle(
                                  foregroundColor: MaterialStateProperty.all(Colors.white),
                                  shape:
                                  MaterialStateProperty.all(BeveledRectangleBorder()),
                                ),
                                onPressed: () {
                                  showDialog(
                                    context: context,
                                    builder: (ctx) {
                                      return PrettyDialog(
                                        content: Column(
                                          children: [
                                            Text(
                                              "${message['product24']}？",
                                              style: TextStyle(
                                                  color: Colors.white, fontSize: 16),
                                              textAlign: TextAlign.center,
                                            ),
                                            SizedBox(
                                              height: 5,
                                            ),
                                            Text(
                                              "${message['product25']}",
                                              style: TextStyle(
                                                  color: Colors.white, fontSize: 13),
                                              textAlign: TextAlign.center,
                                            )
                                          ],
                                        ),
                                        icon: Image.asset(
                                            Utils.getImgPath("ic_forget_password"),
                                            width: 80,
                                            height: 80,
                                            fit: BoxFit.fill,
                                            color: Colors.white),
                                        background:
                                        AssetImage(Utils.getImgPath("ic_alert_dialog")),
                                        gradient: LinearGradient(
                                          begin: Alignment.topCenter,
                                          end: Alignment.bottomCenter,
                                          colors: [
                                            AppColors.secondColor,
                                            AppColors.primaryColor
                                          ],
                                        ),
                                        actions: [
                                          TextButton(
                                            child: Text("${message['product26']}", style: TextStyle(fontSize: 15, color: AppColors.textColor)),
                                            onPressed: () {
                                              Navigator.of(context).pop();
                                            },
                                          ),
                                          TextButton(
                                            child: Text("${message['product27']}", style: TextStyle(fontSize: 15, color: AppColors.primaryColor)),
                                            onPressed: () {
                                              Navigator.of(context).pop();
                                              LoadingApi.func(MallRepository.deleteMallOrderAction(data.order_id), context, complete: (value) {
                                                ToastUtils.show("${message['Success']}", context);
                                                Navigator.of(context).pop(1);
                                              },error: (e){
                                                ToastUtils.show("$e", context);
                                              });
                                            },
                                          ),
                                        ],
                                      );
                                    },
                                  );
                                },
                              ))
                        ],
                      )
                  );
                  break;
              }
              Widget addressView;
              if(data.receipt_name != null || data.receipt_phone != null){
                addressView = Text.rich(
                  TextSpan(
                    children: [
                      TextSpan(text: '$rpName', style: TextStyle(fontSize: 14, color: AppColors.textColor),),
                      TextSpan(text: '   $rpPhone', style: TextStyle(fontSize: 12, color: AppColors.textHintColor),),
                    ],
                  ),
                );
              }else{
                addressView = Text("${message['product8']}",style: TextStyle(fontSize: 14, color: AppColors.textColor),);
              }
              return Stack(
                children: [
                  AspectRatio(
                    aspectRatio: 4,
                    child: Container(
                      decoration: BoxDecoration(
                        gradient: LinearGradient(
                          begin: Alignment.centerLeft,
                          end: Alignment.centerRight,
                          colors: [
                            AppColors.primaryColor,
                            AppColors.secondColor
                          ],
                        ),
                      ),
                    ),
                  ),
                  Column(
                    children: [
                      Expanded(
                        child:Padding(
                            padding: EdgeInsets.only(left: 20, right: 20),
                            child: Container(
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.only(
                                      topLeft: Radius.circular(10),
                                      topRight: Radius.circular(10)),
                                  color: Colors.white,
                                ),
                                padding: EdgeInsets.only(left: 10, right: 10),
                                child: CustomScrollView(
                                  slivers: [
                                    SliverToBoxAdapter(
                                        child: ListTile(
                                          onTap: () {
                                          },
                                          contentPadding: EdgeInsets.only(
                                              left: 0,
                                              right: 0,
                                              top: 12,
                                              bottom: 12),
                                          leading: ClipRRect(
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(25)),
                                             child: Image.asset(
                                                 Utils.getImgPath(
                                                     "ic_order_address"),
                                                 width: 45,
                                                 height: 45),
                                          ),

                                          title:addressView,
                                          subtitle: (Text("${rpAddress == null || rpAddress == "" ? "" : rpAddress}",
                                            style: TextStyle(
                                                fontSize: 12,
                                                color:
                                                AppColors.textColor),
                                            maxLines: 3,
                                          )),
                                        )
                                    ),
                                    SliverToBoxAdapter(
                                        child: Padding(
                                          padding: EdgeInsets.only(bottom: 8),
                                          child: Divider(
                                            thickness: 1,
                                          ),
                                        )),
                                    SliverList(
                                        delegate: SliverChildBuilderDelegate(
                                                (context, index) {
                                              return GestureDetector(
                                                onTap: () {

                                                },
                                                child: ListTile(
                                                  contentPadding: EdgeInsets.symmetric(
                                                      horizontal: 0),
                                                  leading: Stack(
                                                    children: [
                                                      ClipRRect(
                                                        borderRadius: BorderRadius.all(
                                                            Radius.circular(5)),
                                                        child: Image.network(
                                                          "${data.file_url}",
                                                          fit: BoxFit.fill,
                                                          width: 80,height: 80,
                                                          errorBuilder: (context,err,stack){
                                                            return Image.asset(Utils.getImgPath('ic_logo'),width: 80,height: 80,);
                                                          },
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                  title: Column(
                                                    crossAxisAlignment:
                                                    CrossAxisAlignment.start,
                                                    children: [
                                                      Text(
                                                        "${data.goods.name}",
                                                        style: TextStyle(
                                                            fontWeight: FontWeight.bold,
                                                            fontSize: 14,
                                                            color: AppColors.textColor),
                                                      ),
                                                      Text(
                                                        "${data.sku.sku_name}",
                                                        style: TextStyle(
                                                            fontSize: 14,
                                                            color: AppColors
                                                                .textSecondaryColor),
                                                      ),
                                                      Row(
                                                        mainAxisAlignment:
                                                        MainAxisAlignment
                                                            .spaceBetween,
                                                        children: [
                                                          Text(
                                                            "${data.order_price}",
                                                            style: TextStyle(
                                                                fontSize: 14,
                                                                color: AppColors
                                                                    .primaryColor),
                                                          ),
                                                          Text(
                                                            "x ${data.order_number}",
                                                            style: TextStyle(
                                                                fontWeight:
                                                                FontWeight.normal,
                                                                fontSize: 14,
                                                                color: AppColors
                                                                    .textColor),
                                                          ),
                                                        ],
                                                      )
                                                    ],
                                                  ),
                                                ),
                                              );
                                            }, childCount: 1)),
                                    SliverList(
                                        delegate: SliverChildListDelegate(
                                            _buildItems(data))),
                                  ],
                                ))),
                      ),
                      Container(
                          decoration: BoxDecoration(
                            color: Colors.white,
                            boxShadow: [
                              BoxShadow(
                                  color: Colors.black54,
                                  offset: Offset(2.0, 2.0),
                                  blurRadius: 4.0),
                            ],
                          ),
                          child: SafeArea(
                            top: false,
                            bottom: true,
                            left: false,
                            right: false,
                            child: boxBottomChild,
                          )),
                    ],
                  )
                ],
              );
            }
        )
    );
  }

  String _expressRemark;
  List<Widget> _buildItems(OrderListModel model) {
    List<Widget> items = [];
    Widget child;
    List<Widget> tempItems = [];
    child = Padding(
      padding: EdgeInsets.only(top: 20,bottom: 15),
      child:Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            "备注",
          ),
          SizedBox(
            width: 10.0,
          ),
          Flexible(
            child: Text("${model.remark == null ? "无" : "${model.remark}"}",
                maxLines: 2,
                style:
                TextStyle(fontSize: 14.0, color: AppColors.primaryColor)),
          )
        ],
      )

    );
    tempItems.add(child);
    tempItems.add(Divider(
      thickness: 1,
    ));

    child = ListTile(
        contentPadding: EdgeInsets.zero,
        leading: Text(
          "${message['product29']}：${model.order_no.length > 20 ? model.order_no.substring(0, 18) + "..." : model.order_no}",
        ),
        trailing: GestureDetector(
          onTap: () {
            ClipboardData data = new ClipboardData(text: model.order_no);
            Clipboard.setData(data);
            ToastUtils.show("${message['trad117']}", context);
          },
          child: Text(
            "${message['trad81']}",
            style: TextStyle(color: AppColors.primaryColor),
          ),
        ));
    tempItems.add(child);
    tempItems.add(Divider(
      thickness: 1,
    ));
    if (model.create_time != null) {
      child = ListTile(
        contentPadding: EdgeInsets.zero,
        leading: Text(
          "${message['product20']}  ${model.create_time}",
        ),
      );
      tempItems.add(child);
      tempItems.add(Divider(
        thickness: 1,
      ));
    }

    if(model.order_state == "2"){
      child = ListTile(
          contentPadding: EdgeInsets.zero,
          leading: Text(
            "${message['product30']}：${model.logistics_no ?? '${message['product36']}'}",
          ),
          trailing: GestureDetector(
            onTap: () {
              ClipboardData data = new ClipboardData(text: model.logistics_no);
              Clipboard.setData(data);
              ToastUtils.show("${message['trad117']}", context);
            },
            child: Text(
              "${message['trad81']}",
              style: TextStyle(color: AppColors.primaryColor),
            ),
          ));
      tempItems.add(child);
      tempItems.add(Divider(
        thickness: 1,
      ));

      child = ListTile(
        contentPadding: EdgeInsets.zero,
        leading: Text(
          "${message['product31']}：${model.logistics_name ?? '${message['product36']}'}",
        ),
      );
      tempItems.add(child);
      tempItems.add(Divider(
        thickness: 1,
      ));
    }


    child = ListTile(
      contentPadding: EdgeInsets.zero,
      leading: Text(
        "${message['product12']}",
      ),
      trailing: Text(
        detailPrice(model),
        style: TextStyle(color: AppColors.primaryColor),
      ),
    );
    tempItems.add(child);
    tempItems.add(Divider(
      thickness: 1,
    ));

    Widget temp = Column(
      children: tempItems,
    );
    items.add(temp);
    // items.add(child);

    return items;
  }

  String detailPrice(OrderListModel model){
    return "无忧积分:${model.order_total_price}";
    if(model.order_no.startsWith("xf")){
      return "消费积分:${model.order_total_price}";
    }else if(model.order_no.startsWith("ll")){
      return "无忧积分:${model.order_total_price}";
    }else{
      return "消费积分:${model.order_total_price}";
    }
  }
}